package com.example.supermarket;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class InputActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_input);

        Intent intent=getIntent();
        int position=intent.getIntExtra("position",0);

        EditText editTextName=findViewById(R.id.edit_text_name);
        EditText editTextPrice=findViewById(R.id.edit_text_price);
        String name=intent.getStringExtra("name");
        double price=intent.getDoubleExtra("price",0);
        if(null!=name){
            editTextName.setText(name);
            editTextPrice.setText(String.valueOf(price));
        }

        Button buttonOk=this.findViewById(R.id.button_ok);
        buttonOk.setOnClickListener(view -> {
            Intent intent1 =new Intent();
            intent1.putExtra("position",position);
            intent1.putExtra("name",editTextName.getText().toString());
            intent1.putExtra("price",Double.parseDouble(editTextPrice.getText().toString()));
            setResult(ShopItemFragment.RESULT_CODE_ADD_DATA, intent1);
            InputActivity.this.finish();
        });
    }
}